﻿using JYJJ.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Utility.Models;
using Hxj.Data;
using System.Data;
using Utility.Helper;

namespace JYJJ.BLL.Impl
{
    public class ServiceDonate
    {
        BaseService dal = new BaseService();
        public model_Donate GetDonateModel(int id)
        {
            return dal.GetModel<model_Donate>(model_Donate._.ID == id);
        }
        public model_Donate_Order GetDonateOrderModel(string ID)
        {
            return GetDonateOrderModel(model_Donate_Order._.Id == ID);
        }
        public model_Donate_Order GetDonateOrderModelByOrderID(string OrderID)
        {
            return GetDonateOrderModel(model_Donate_Order._.orderId == OrderID);
        }

        public DataTable GetDonateOrderTable(out int rowCount, WhereClip wcp, OrderByClip order, int pageIndex, int pageSize)
        {
            rowCount = dal.ToCount<model_Donate_Order>(wcp);
            return DbHelper.GetDatabase().From<model_Donate_Order>() //选择表   
                                                .Select(model_Donate_Order._.All)  //设置选择的字段数目
                                               .Page(pageSize, pageIndex)  //分页显示
                                               .Where(wcp)   //条件
                                               .OrderBy(order)   //排序
                                               .ToDataTable();   //返回datatable




        }

        public model_Donate_Order GetDonateOrderModel(WhereClip wcp)
        {
            return dal.GetModel<model_Donate_Order>(wcp);
        }

        public void Save(model_Donate_Order order)
        {
            dal.Save<model_Donate_Order>(order);
        }

        public void UpdateDonateMoney(model_Donate_Order order)
        {
            dal.ExecuteNonQuery("UPDATE model_Donate SET Obtain=ISNULL(Obtain,0)+" + order.payMoney.ToString() + "  WHERE ID='" + order.orderId.ToString() + "'");
        }
    }
}
